package tech.dort.dortware.impl.modules.exploit;

import com.google.common.eventbus.Subscribe;
import net.minecraft.entity.player.EntityPlayer;
import tech.dort.dortware.api.module.Module;
import tech.dort.dortware.api.module.ModuleData;
import tech.dort.dortware.api.property.impl.NumberValue;
import tech.dort.dortware.impl.events.UpdateEvent;
import tech.dort.dortware.impl.utils.time.Stopwatch;

import java.util.stream.Collectors;

public class SpamTP extends Module {

    private final Stopwatch stopwatch = new Stopwatch();
    private final NumberValue delay = new NumberValue("Delay", this, 3, 1, 10, true);

    public SpamTP(ModuleData moduleData) {
        super(moduleData);
        register(delay);
    }

    @Subscribe
    public void onUpdate(UpdateEvent event) {
        for (EntityPlayer player : mc.theWorld.playerEntities.stream().filter(player -> player != mc.thePlayer && !player.getName().equals("Carpenter")).collect(Collectors.toList())) {
            if (stopwatch.timeElapsed(delay.getValue().longValue() * 1000L)) {
                mc.thePlayer.sendChatMessage("/tp " + player.getName() + " " + mc.thePlayer.getName());
                stopwatch.resetTime();
            }
        }
    }
}
